#!/usr/bin/env python
# encoding: utf-8
"""
main.py

Created by Paul Bergeron on 2009-02-02.
"""
import pyglet
import tygger_pyglet

def main():
	screen_width, screen_height = 1024, 768
	window = pyglet.window.Window(width=screen_width, height=screen_height)
	
	tygger_pyglet.tygger.init(width=screen_width*2, height=screen_height*2, gravity=(0,-9.81))
	
	pyglet.resource.path = ['img']
	pyglet.resource.reindex()
	
	ground_image = pyglet.resource.image('ground.png')
	ground_image.anchor_x = ground_image.width // 2
	ground_image.anchor_y = ground_image.height // 2
	ball_image = pyglet.resource.image('ball.png')
	ball_image.anchor_x = ground_image.width // 2
	ball_image.anchor_y = ground_image.height // 2
	
	batch = pyglet.graphics.Batch()
	
	ground = tygger_pyglet.PygletPhysicsStaticCollisionBody(ground_image, batch=batch, x=512, y=256)
	ball = tygger_pyglet.PygletPhysicsCollisionBody(ball_image, batch=batch, x=512, y=768)
	
	@window.event
	def on_draw():
		window.clear()
		batch.draw()
	
	def update(dt):
		tygger_pyglet.tygger.time_step()
		print ball.phys_body.position
		ball.physics_sync()
	
	pyglet.clock.schedule(update)
	print ground.phys_shape.vertices
	pyglet.app.run()

if __name__ == '__main__':
	main()
